package com.liu.utils;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 *
 * @author liuchengjie
 */
public class StreamUtils {
    /**
     * 将输入流转换成byte[],即可以把文件的内容读入到byte[]
     * @param is
     * @return
     * @throws IOException
     */
    public static byte[] streamToByteArray(InputStream is) throws IOException {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        byte[] bytes = new byte[1024];
        int len;
        while ((len = is.read(bytes)) != -1) {
            bos.write(bytes,0,len);
        }
        byte[] byteArray = bos.toByteArray();
        bos.close();
        return byteArray;
    }


}
